l = [1, 2, 3, 4, 5, 6, 7]
fcount = 0
# for循环计数
for i in l:
    fcount += 1
print(f"一共有：{fcount}")

# while循环计数
i = 0
wcount = 0
while i < 100:
    i += 3
    wcount += 1
print(f"一共有：{wcount}")


# for斐波那契
i = 0
j = 1
l1 = []
l1.append(i)
l1.append(j)
for n in range(0, 5):
    i += j
    l1.append(i)
    j += i
    l1.append(j)
print(l1)

# while斐波那契
i = 0
j = 1
l2 = []
l2.append(i)
l2.append(j)
while True:
    i += j
    if i < 100:
        l2.append(i)
    else:
        break
    j += i
    if j < 100:
        l2.append(j)
    else:
        break
print(l2)

# 计算器

class ParamsError(Exception):
     pass
def add(a, b):
    print(a, "+", b, "=")
    return a + b

def minus(a, b):
    print(a, "-", b, "=")
    return a - b

def mul(a, b):
    print(a, "*", b, "=")
    return a * b

def div(a, b):
    try:
        print(a, "/", b, "=")
        return a / b
    except ZeroDivisionError:
        raise ParamsError("分母不可以为0")
    finally:
        print("function div end")

def be_div(a, b):
    print(a, "//", b, "=")
    return a // b

def rem(a, b):
    print(a, "%", b, "=")
    return a % b

def root(a):
    print(a, "^1/2 =")
    return a ** (1/2)

a = int(input("请输入数字："))
print("加法运算请输入'+'，减法运算请输入’-‘，乘法运算请输入’*‘，除法运算请输入’/‘")
print("取商运算请输入‘//’，取余运算请输入‘%’，开方运算请输入‘开方’")
symbol = str(input("请输入要执行的操作："))
if str(symbol) == "开方":
    print(root(a))
else:
    b = int(input("请输入数字："))
    if str(symbol) == "+":
        print(add(a, b))
    elif str(symbol) == "-":
        print(minus(a, b))
    elif str(symbol) == "*":
        print(mul(a, b))
    elif str(symbol) == "/":
        print(div(a, b))
    elif str(symbol) == "//":
        print(be_div(a, b))
    elif str(symbol) == "%":
        print(rem(a, b))
    else:
        print("无法进行该运算")